#!/usr/bin/perl
#Programmer: Rory Carmichael
#Purpose: split a summary file into a spreadsheet, and a folder filled with histogram data, incidentally creates visualizations
#NOTE: deprecated due to Google API changes
#Usage: split_summaries.pl folder_name input_file

my $folder = shift;
mkdir $folder;
my $header;
my $cur_clust;
my $cur_hist;
while (my $line = <>) {
	chomp $line;
	if($line =~ /^cluster/) {
		if(defined($cur_clust)) {
			print STDERR `echo '$cur_hist'`;
			print STDERR `echo '$cur_hist' | ./g_plots.pl > gtmp.png`;
			print STDERR `convert -page +0+0 gtmp.png -page +300+0 rtmp.png -background white -transparent-color white -layers merge +repage $folder/$cur_clust.png`;
			undef($cur_clust);
			undef($cur_hist);
		}
		if(!defined($header)) {
			$header = $line;
			print $header . "\n";
		}
		my $vline = <>;
		my $radar = $header . "\n" . $vline;
		#We are currently only printing and making csvs of the "interesting" plots
		if($vline =~ /\t0\t/) {
			print STDERR `echo '$radar' | ./radar_plot.pl > rtmp.png`;
			$cur_clust = [split(/\s+/, $vline)]->[0];
			print $vline;
		} else {
			undef($cur_clust);
			undef($cur_hist);
		}
	} else {
		$cur_hist .= $line ."\n";
	}
}
if(defined($cur_clust)) {
	print STDERR `echo '$cur_hist' | ./g_plots.pl > gtmp.png`;
	print STDERR `convert -page +0+0 gtmp.png -page +300+0 rtmp.png -background white -transparent-color white -layers merge +repage $folder/$cur_clust.png`;
	undef($cur_clust);
	undef($cur_hist);
}
